#include <bits/stdc++.h>

#include <atcoder/all>
#define LL long long
using namespace std;
using namespace atcoder;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;

  cin >> s;
  vector<int> sa = suffix_array(s);
  vector<int> lcp = lcp_array(s, sa);

  int n = s.size();
  LL ans = (LL)n * (n + 1) / 2;
  for (int len : lcp) {
    ans -= len;
  }
  cout << ans << "\n";
  return 0;
}
